// SetScriptTimePlugin
const HtmlWebpackPlugin = require('html-webpack-plugin');

class SetScriptTimePlugin {
  constructor(opts) {
    this.opts = opts
  }

  apply(compiler) {
    compiler.hooks.compilation.tap('SetScriptTimePlugin', (compilation, callback) => {

      HtmlWebpackPlugin.getHooks(compilation).beforeAssetTagGeneration.tapAsync('SetScriptTimePlugin', (htmlPluginData, callback) => {
        htmlPluginData.assets.js = htmlPluginData.assets.js.map(item => item + '?' + new Date().getTime())

        callback(null, htmlPluginData)
      })
    })
  }
}

module.exports = SetScriptTimePlugin
